package com.xing.other;

public class EnumClass {

    enum RewardType {
        COUPON("coupon"),
        SVIP("svip"),
        INSTABOOK("instabook");

        private String name;

        private RewardType(String name) {
            this.name = name;
        }

        public static RewardType from(String typeName) {
            for (RewardType type : RewardType.values()) {
                if (type.getName().equals(typeName)) {
                    return type;
                }
            }
            return null;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }


    enum ExternalRewardActiviyItemTypeEnum {
        SKU("sku"),
        COUPON(RewardType.COUPON.getName()),
        SVIP(RewardType.SVIP.getName()),;
        private String itemType;

        ExternalRewardActiviyItemTypeEnum(String itemType) {
            this.itemType = itemType;
        }

        public String getItemType() {
            return this.itemType;
        }

        public static ExternalRewardActiviyItemTypeEnum from(String itemType) {
            for (ExternalRewardActiviyItemTypeEnum itemTypeEnum : ExternalRewardActiviyItemTypeEnum.values()) {
                if (itemTypeEnum.itemType.equals(itemType)) {
                    return itemTypeEnum;
                }
            }
            return null;
        }

    }

    enum RewardEnum {
        REWARD_SKU(ExternalRewardActiviyItemTypeEnum.SKU) {
            @Override
            void reward(long memberId, String itemId) {
                System.err.println("-----hello");
            }
        },
        REWARD_COUPON(ExternalRewardActiviyItemTypeEnum.COUPON) {
            @Override
            void reward(long memberId, String itemId) {

            }
        },
        REWARD_SVIP(ExternalRewardActiviyItemTypeEnum.SVIP) {
            @Override
            void reward(long memberId, String itemId) {

            }
        },;

        private ExternalRewardActiviyItemTypeEnum externalRewardActiviyItemTypeEnum;

        RewardEnum(ExternalRewardActiviyItemTypeEnum externalRewardActiviyItemTypeEnum) {
            this.externalRewardActiviyItemTypeEnum = externalRewardActiviyItemTypeEnum;
        }

        abstract void reward(long memberId, String itemId);

        public static RewardEnum fromItemTypeEnum(ExternalRewardActiviyItemTypeEnum itemTypeEnum) {
            for (RewardEnum rewardEnum : RewardEnum.values()) {
                if (rewardEnum.externalRewardActiviyItemTypeEnum.equals(itemTypeEnum)) {
                    return rewardEnum;
                }
            }
            return null;
        }
    }

    public static void main(String[] args) {
        RewardEnum.fromItemTypeEnum(ExternalRewardActiviyItemTypeEnum.SKU).reward(1, "1");
    }

}
